package com.mh.main.caipiao;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mh.caipiao.entity.CaiPiaoEntity;
import com.mh.caipiao.entity.ResDataEntity;
import com.mh.caipiao.CaiPiaoStart;
import com.mh.caipiao.service.impl.ResDataService;
import com.mh.mh.util.MyUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class CaiPiaoKid extends CaiPiaoStart {

    @Autowired
    private ResDataService resDataService;


    /**
     * 水平方向对比
     * @param list
     * @param czxMax
     * @param codeIndexMax
     */
    public void sp(List<CaiPiaoEntity> list, int czxMax, int codeIndexMax){

        for(int i = 0; i<= czxMax; i++){


            for(int j = 0; j<= codeIndexMax; j++){
                int codeIndex = j;
                System.out.println("----- "+j+" ----- ");

                for(CaiPiaoEntity caiPiaoEntity : list){
                    ResDataEntity resData = new ResDataEntity();

                    resData.setCodeNum(j);
                    // 设置分析类型
                    setResType(i, resData);
                    // 设置结果
                    setResContent(i, resData, caiPiaoEntity, codeIndex);

                }
            }
        }


    }


    private void setResType(int i, ResDataEntity resData){
        int czx = i;
        if(czx == 0){
            System.out.println("========= 0天干 =========");
//            resData.setResType("天干");
        }else if(czx == 1){
            System.out.println("========= 1地支 =========");
//            resData.setResType("地支");
        }else if(czx == 2){
            System.out.println("========= 2农历 =========");
//            resData.setResType("农历");
        }else if(czx == 3){
            System.out.println("========= 3阳历 =========");
//            resData.setResType("阳历");
        }else if(czx == 4){
            System.out.println("========= 4纳音 =========");
//            resData.setResType("纳音");
        }
    }

    private void setResContent(int i, ResDataEntity resData, CaiPiaoEntity caiPiaoEntity, int codeIndex){

        String kjDate = caiPiaoEntity.getKjDate();

        resData.setKjDate(kjDate);

        String tg = caiPiaoEntity.getTg();
        String dz = caiPiaoEntity.getDz();
        String oldDay =  MyUtil.getLastStr(caiPiaoEntity.getOldDay());
        String newDay = MyUtil.getLastStr(caiPiaoEntity.getNewDay());
        String ny = caiPiaoEntity.getNy();// 纳音就是五行，不需要转换
//                    String code = MyUtil.getLastStr(caiPiaoEntity.getCode().split("-")[0].split(",")[codeIndex]);
        String code1 = caiPiaoEntity.getCode().replace("-",",");
        String code = MyUtil.getLastStr(code1.split(",")[codeIndex]);


        // 五行属性
        String tgwx = wuXingRelationUtil.dataMap.get(tg);
        String dzwx = wuXingRelationUtil.dataMap.get(dz);
        String oldDaywx = wuXingRelationUtil.dataMap.get(oldDay);// 农历五行
        String newDaywx = wuXingRelationUtil.dataMap.get(newDay);// 阳历五行
        String codewx = wuXingRelationUtil.dataMap.get(code);// 开奖号码五行


        int czx = i;
        String wx = "";// 五行合并，用于获取生克关系
        if(czx == 0){
            wx = tgwx + codewx;
        }else if(czx == 1){
            wx = dzwx + codewx;
        }else if(czx == 2){
            wx = oldDaywx + codewx;
        }else if(czx == 3){
            wx = newDaywx + codewx;
        }else if(czx == 4){
            wx = ny + codewx;
        }

        String fx = wuXingRelationUtil.wxskMap.get(wx);// 生克方向

//                    System.out.println(wx+"-"+fx);
        System.out.println(fx);

        resData.setResContent(fx);

        resDataService.saveOrUpdate(resData, new LambdaQueryWrapper<ResDataEntity>()
                .eq(ResDataEntity::getKjDate, resData.getKjDate())
//                .eq(ResDataEntity::getResType, resData.getResType())
                .eq(ResDataEntity::getCodeNum, resData.getCodeNum())
        );
//        resDataService.saveOrUpdate(resData);
    }




}
